/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interfaz;

import Negocio.Conexion;
import Negocio.Login;
import Negocio.Validaciones;
import java.sql.SQLException;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author Usuario
 */
public class Principal extends javax.swing.JFrame {
    int bandera = 0;
    public String cedula ;
    Validaciones validar = new Validaciones();
    /**
     * Creates new form Pinrcipal
     */
    public Principal() {
        
        
        try
        {
           UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        }
        catch(Exception e)
        {
        }
        initComponents();
        this.setLocationRelativeTo(null);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        InterfazLogin = new javax.swing.JDialog();
        txtContraseña = new javax.swing.JPasswordField();
        cmdIngresar = new javax.swing.JButton();
        cmdCancelar = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        cmdAdministrador = new javax.swing.JButton();
        cmdAyundante = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        cmdExalumno = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        cmdIngresar.setText("Ingresar");
        cmdIngresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdIngresarActionPerformed(evt);
            }
        });

        cmdCancelar.setText("Cancelar");
        cmdCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdCancelarActionPerformed(evt);
            }
        });

        jLabel2.setText("Contraseña:");

        txtUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUsuarioActionPerformed(evt);
            }
        });

        jLabel3.setText("Usuario:");

        javax.swing.GroupLayout InterfazLoginLayout = new javax.swing.GroupLayout(InterfazLogin.getContentPane());
        InterfazLogin.getContentPane().setLayout(InterfazLoginLayout);
        InterfazLoginLayout.setHorizontalGroup(
            InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 345, Short.MAX_VALUE)
            .addGroup(InterfazLoginLayout.createSequentialGroup()
                .addGap(64, 64, 64)
                .addGroup(InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(InterfazLoginLayout.createSequentialGroup()
                        .addGroup(InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3))
                        .addGap(38, 38, 38))
                    .addGroup(InterfazLoginLayout.createSequentialGroup()
                        .addComponent(cmdIngresar)
                        .addGap(18, 18, 18)))
                .addGroup(InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(txtUsuario)
                        .addComponent(txtContraseña, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE))
                    .addGroup(InterfazLoginLayout.createSequentialGroup()
                        .addGap(8, 8, 8)
                        .addComponent(cmdCancelar)))
                .addContainerGap(83, Short.MAX_VALUE))
        );
        InterfazLoginLayout.setVerticalGroup(
            InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 180, Short.MAX_VALUE)
            .addGroup(InterfazLoginLayout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtContraseña, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addGroup(InterfazLoginLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdIngresar)
                    .addComponent(cmdCancelar))
                .addGap(30, 30, 30))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("MENU DE ACCESO");
        setResizable(false);

        cmdAdministrador.setText("ADMINISTRADOR...");
        cmdAdministrador.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdAdministradorActionPerformed(evt);
            }
        });

        cmdAyundante.setText("AYUDANTE...");
        cmdAyundante.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdAyundanteActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 24));
        jLabel1.setText("MENU DE ACCESO");

        cmdExalumno.setText("EXALUMNO...");
        cmdExalumno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmdExalumnoActionPerformed(evt);
            }
        });

        jButton2.setText("X");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("?");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(68, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 66, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(cmdAdministrador, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(14, 14, 14)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(22, 22, 22)
                                .addComponent(cmdAyundante, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(31, 31, 31)
                                .addComponent(cmdExalumno, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(56, 56, 56))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel1)
                .addGap(55, 55, 55)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cmdAdministrador, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdAyundante, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmdExalumno, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(86, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton3ActionPerformed

    private void cmdExalumnoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdExalumnoActionPerformed
        // TODO add your handling code here:
        bandera = 3;
        InterfazLogin.setSize(360, 220);
        InterfazLogin.setLocationRelativeTo(this);
        InterfazLogin.setModal(true);
        InterfazLogin.setVisible(true);
        
        
    }//GEN-LAST:event_cmdExalumnoActionPerformed

    private void txtUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUsuarioActionPerformed

        // TODO add your handling code here:}//GEN-LAST:event_txtUsuarioActionPerformed
    }
        private void cmdCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCancelarActionPerformed
        // TODO add your handling code here:
         InterfazLogin.dispose();
    }//GEN-LAST:event_cmdCancelarActionPerformed

    private void cmdIngresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdIngresarActionPerformed
       
       // InterfazExAlumno interf = new InterfazExAlumno();
        Conexion log = new Conexion();
        cedula = txtUsuario.getText();
        String contraseña = txtContraseña.getText();
        
        System.out.println(contraseña);
        
        Login ingresar = new Login();
        System.out.println(bandera);
        try 
        {
            if (validar.ValidarCedula(cedula)==true)
            {
                boolean band = ingresar.Logear(cedula, contraseña, bandera);
                if (band == true)
                {
                    if (bandera == 1 )
                    {
                        InterfazAdmin admin = new InterfazAdmin();
                        admin.setVisible(true);
                        InterfazLogin.setVisible(false);
                        this.setVisible(false);
                        admin.enviarCedula(cedula);
                        log.ingersarLog(cedula,"INGRESO ADMISTRADOR");
                    } 
                    else if (bandera == 2 )
                    {
                        InterfazExAlumno ayud = new InterfazExAlumno();
                        ayud.setVisible(true);
                        InterfazLogin.setVisible(false);
                        this.setVisible(false);
                        ayud.enviarCedula(cedula,bandera);
                        log.ingersarLog(cedula,"INGRESO AYUDANTE");
                    }
                    else if (bandera == 3 )
                    {

                        InterfazExAlumno exal = new InterfazExAlumno();
                        exal.setVisible(true);
                        InterfazLogin.setVisible(false);
                        this.setVisible(false);
                        exal.enviarCedula(cedula,bandera);
                        

                    }
                }
                else
                {
                    JOptionPane.showMessageDialog(this, "Datos Incorrectos.");
                    
                    
                }
            }
            else
            {
                JOptionPane.showMessageDialog(this, "Cedula Incorrecta.");
            }

        } 
        catch (SQLException ex) 
        {
            ex.printStackTrace();
        }
        
    }//GEN-LAST:event_cmdIngresarActionPerformed

    private void cmdAyundanteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAyundanteActionPerformed
        // TODO add your handling code here:
        bandera = 2 ;
        InterfazLogin.setSize(360, 220);
        InterfazLogin.setLocationRelativeTo(this);
        InterfazLogin.setModal(true);
        InterfazLogin.setVisible(true);
        
        
    }//GEN-LAST:event_cmdAyundanteActionPerformed

    private void cmdAdministradorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAdministradorActionPerformed
        // TODO add your handling code here:
        bandera = 1 ;
        InterfazLogin.setSize(360, 220);
        InterfazLogin.setLocationRelativeTo(this);
        InterfazLogin.setModal(true);
        InterfazLogin.setVisible(true);
        
       
    }//GEN-LAST:event_cmdAdministradorActionPerformed
   
    public String getCedula()
    {
     return cedula;
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog InterfazLogin;
    private javax.swing.JButton cmdAdministrador;
    private javax.swing.JButton cmdAyundante;
    private javax.swing.JButton cmdCancelar;
    private javax.swing.JButton cmdExalumno;
    private javax.swing.JButton cmdIngresar;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPasswordField txtContraseña;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables
}
